﻿@{
    ViewData["Title"] = "UpdateClient";
    Layout = null;
}
<html>
<head>
    
    <link href="~/layui/css/layui.css" rel="stylesheet" />
    <script src="~/layui/layui.js"></script>
    <script src="~/libs/jquery/jquery.js"></script>
</head>
<body>
    <!-- 给容器追加 class="layui-form-pane"，即可显示为方框风格 -->
    <form class="layui-form layui-form-pane" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">客户编码</label>
            <div class="layui-input-block">
                <input type="text" name="ClientCode" id="ClientCode" autocomplete="off" placeholder="请输入客户编码" disabled lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户名称</label>
            <div class="layui-input-block">
                <input type="text" name="ClientName" id="ClientName" autocomplete="Name" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户英文名称</label>
            <div class="layui-input-block">
                <input type="text" name="ClientEnName" id="ClientEnName" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户类型</label>
            <div class="layui-input-inline">
                <select name="ClientType" id="ClientType" lay-filter="aihao">
                    <option value="请选择">请选择</option>
                    <option value="企业客户">企业客户</option>
                    <option value="个人">个人</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">客户简介</label>
            <div class="layui-input-block">
                <textarea name="ClientDesc" id="ClientDesc" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">客户地址</label>
            <div class="layui-input-block">
                <textarea name="Address" id="Address" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户官网地址</label>
            <div class="layui-input-block">
                <input type="text" name="WebSite" id="WebSite" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户邮箱地址</label>
            <div class="layui-input-block">
                <input type="text" name="Email" id="Email" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户电话</label>
            <div class="layui-input-block">
                <input type="text" name="Tel" id="Tel" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客户Logo</label>
            <div class="layui-input-block">
                <input type="text" name="ClientLogo" id="ClientLogo" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-block">
                <input type="text" name="Contact" id="Contact" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系人电话</label>
            <div class="layui-input-block">
                <input type="text" name="ContactTel" id="ContactTel" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系人邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="ContactEmail" id="ContactEmail" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">社会信用代码</label>
            <div class="layui-input-block">
                <input type="text" name="CreditCode" id="CreditCode" autocomplete="off" placeholder="请输入" lay-verify="required" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">客户备注</label>
            <div class="layui-input-block">
                <textarea name="Remark" id="Remark" placeholder="请输入内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" type="button" lay-submit lay-filter="btnUpdate">确认</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>
@*     <script src="~/layui-v2.5.6/layui/layui.js"></script>
    <script src="~/libs/jquery/jquery.js"></script> *@
    <script>
        layui.use(['form', 'laydate'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.$;
            var updateclient = JSON.parse(localStorage.getItem("updateclient"));
            console.log(updateclient);
            
            $("[name=ClientCode]").val(updateclient.ClientCode)
            $("[name=ClientName]").val(updateclient.ClientName)
            $("[name=ClientEnName]").val(updateclient.ClientEnName)
            $("[name=ClientDesc]").val(updateclient.ClientDesc)
            $("[name=ClientType]").val(updateclient.ClientType)
            form.render('select');
            $("[name=ClientLogo]").val(updateclient.ClientLogo)
            $("[name=Address]").val(updateclient.Address)
            $("[name=WebSite]").val(updateclient.WebSite)
            $("[name=Email]").val(updateclient.Email)
            $("[name=Tel]").val(updateclient.Tel)
            $("[name=Contact]").val(updateclient.Contact)
            $("[name=ContactTel]").val(updateclient.ContactTel)
            $("[name=ContactEmail]").val(updateclient.ContactEmail)
            $("[name=CreditCode]").val(updateclient.CreditCode)
            $("[name=Remark]").val(updateclient.Remark)
            // 提交事件
            form.on('submit(btnUpdate)', function (data) {
                data = data.field;
                console.log(data)
                updateclient.ClientCode = data.ClientCode;
                updateclient.ClientName = data.ClientName;
                updateclient.ClientEnName = data.ClientEnName;
                updateclient.ClientDesc = data.ClientDesc;
                updateclient.ClientType = data.ClientType;
                updateclient.ClientLogo = data.ClientLogo;
                updateclient.Address = data.Address;
                updateclient.WebSite = data.WebSite;
                updateclient.Email = data.Email;
                updateclient.Tel = data.Tel;
                updateclient.Contact = data.Contact;
                updateclient.ContactTel = data.ContactTel;
                updateclient.ContactEmail = data.ContactEmail;
                updateclient.CreditCode = data.CreditCode;
                updateclient.Remark = data.Remark;

                $.get("/QiData/UpdateClientById", updateclient,
                    res => {
                        if (res) {
                            layer.msg('修改客户成功', {
                                icon: 1,
                                time: 1000
                            }, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                                window.location = '/QiData/Mdclient';
                            });
                        }
                        else {
                            layer.msg('修改客户失败！', {
                                icon: 1,
                                time: 1000
                            });
                        }
                    }
                )
            });
        });
    </script>
</body>
</html>
